package com.cn.kabalifeuser.ui.my.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.utils.RxToast;
import com.cn.kabalifeuser.utils.TimeUtils;
import com.cn.kabalifeuser.view.CustEdInput;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 晓林 on 2020/9/10.
 * function:意见
 */
public class OpinionActivity extends IBaseActivity<OpinionView, OpinionPresenter> implements OpinionView {
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.tv_count_num)
    TextView tvCountNum;

    @Override
    protected OpinionPresenter createPresenter() {
        return new OpinionPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_opinion;
    }

    @Override
    public void onReLoggedIn(String msg) {
        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return getMe();
    }

    @Override
    public void onOpinionSuccess(MsgBean bean) {

        RxToast.success(bean.getMsg());
        finish();
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);

        setTitleBar("意见反馈");
        etContent.addTextChangedListener(new CustEdInput(300, etContent, tvCountNum));
        tvCountNum.requestFocus();
        //init
        CustEdInput.configCount();
        etContent.setSelection(etContent.length()); // 将光标移动最后一个字符后面
    }


    @OnClick(R.id.tv_btn_next)
    public void onViewClicked() {
        hideKeyboard(etContent);
        if (!TextUtils.isEmpty(etContent.getText().toString().trim())) {
            mPresenter.onOpinionData(
                    LoginHelper.getLonginData().getResult(),
                    etContent.getText().toString().trim()
            );
        } else
            RxToast.error("请输入您的宝贵意见");
    }
}
